// pages/dis_dil/dis_d5.js
var app = getApp();
Page({
  data: {
    scene: ''
  },
  onLoad: function (options) {
    var that = this
    var scene_img = '' //这里添加图片的地址
    that.setData({
      scene: scene_img
    })
  },
  previewImage: function (e) {
    wx.previewImage({
      urls: this.data.scene.split(',')
      // 需要预览的图片http链接  使用split把字符串转数组。不然会报错
    })
  },
  /****长按保存图片 */
  saveImg: function () {
    let that = this
    wx.getSetting({
      success(res) {
        //未授权 先授权 然后保存
        if (!res.authSetting['scope.writePhotosAlbum']) {
          wx.authorize({
            scope: 'scope.writePhotosAlbum',
            success(re) {
              that.saveToBlum();
            }
          })
        } else {
          //已授 直接调用保存到相册方法
          that.saveToBlum();
        }
      }
    })
  },
  //保存到相册方法
  saveToBlum: function () {
    console.log("save img")
    let imgUrl = '/static/images/erweima.png';
    wx.getImageInfo({
      src: imgUrl,
      success: function (ret) {
        var path = ret.path;
        console.log(ret)
        wx.saveImageToPhotosAlbum({
          filePath: path,
          success(result) {
            wx.showToast({
              title: '保存成功',
              icon: 'success'
            })
          },
        })
      }
    })
  },
})